#include "stdafx.h"
#include <irrKlang.h>

class Player
{
public:

	Player(Ogre::SceneManager * sceneMgr,OgreNewt::World* W,OgreNewt::MaterialID* stoji,OgreNewt::MaterialID* ide,OgreNewt::MaterialID* grb_mat,OgreNewt::MaterialID* flg_mat,irrklang::ISoundEngine* sEngine);
    ~Player ();

	void move_callback(OgreNewt::Body* me, float timeStep, int threadIndex );
	void move_callback_nothing(OgreNewt::Body* me, float timeStep, int threadIndex );
    void grabbed_callback(OgreNewt::Body* me, float timeStep, int threadIndex );
	void default_callback(OgreNewt::Body* me, float timeStep, int threadIndex );
	void climb_callback(OgreNewt::Body* me, float timeStep, int threadIndex );

	void setPremenne(Ogre::Real* postPFall,Ogre::Matrix4* invVP,Ogre::Matrix4* prevVP) {postPr1=postPFall; iVP=invVP; pVP=prevVP;}
	void update(Ogre::Real time);
	void updateStats();
	void updateHead(Ogre::Real time);
	void manageFall();
	void pressedKey(const OIS::KeyEvent &arg);
	void releasedKey(const OIS::KeyEvent &arg);
	void pressedMouse(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	void releasedMouse(const OIS::MouseEvent &arg, OIS::MouseButtonID id);
	void movedMouse(const OIS::MouseEvent &e);
	void rotateCamera(Ogre::Real hybX,Ogre::Real hybY);
	void setVlavo(bool b){vlavo=b;}
	void setVpravo(bool b){vpravo=b;}
	void setVpred(bool b){vpred=b;}
	void setVzad(bool b){vzad=b;}
	void setCrouch(char b);
	void startClimbing(char type);
	void stopClimbing();
	void stopMoving() {vlavo=false; vpravo=false; vpred=false; vzad=false;};
	void setBaloonTrack(Ogre::SceneNode* t){track=t;}
	void walkingSound(Ogre::Real time);
	char getCrouch(){return crouch;}
	Ogre::Vector3 getParam(){return Ogre::Vector3(climb_yaw);}
	OgreNewt::Body* getBody(){return pbody;}
	void skoc();
	bool canClimb(char smer);
	bool jeNazemi(){return nazemi;}
	Ogre::SceneNode* getCamNode(){return camnode;}
	void tryToGrab();


private:
    OgreNewt::World* m_World;
	Ogre::Real tslf,slowingDown;
	Ogre::SceneManager * mSceneMgr;
	OgreNewt::Body* pbody, *Gbody;
	Ogre::Vector3 climb_normal;
	irrklang::ISoundEngine* soundEngine;
	bool stoji,vpravo,vlavo,vzad,vpred,nazemi,visi,leti,grabbed,onRope;
	Ogre::Vector3 smer,gNormal,climbDir,lastSpeed;
	OgreNewt::MaterialID* stoji_mat, *ide_mat,*flag_mat,*grab_mat;
	Ogre::SceneNode* camnode, *necknode,* headnode;
	OgreNewt::ConvexCollisionPtr col_p;
	Ogre::Real camAngle,veee,crouch_am,climbTimer,movespeed,walkSoundTimer,climb_yaw,climb_pitch,climb_move_side,climb_move_vert,climb_pullup;
	char fallPitch,jumpPitch,crouch,cameraWalkFinisher,is_climbing;
	OgreNewt::BallAndSocket* climbJoint;
	Ogre::Real fallPitchsize,jumpPitchsize,cam_walking,head_turning,pullupPos;
	Ogre::SceneNode* track;
	int groundID,mouseX,mouseY;
	OgreNewt::UpVector* uv;
	OgreNewt::UpVector* uv2;
	Ogre::Vector3 gADT;
	Ogre::Real gLDT;
	Ogre::Real* postPr1;
	Ogre::Matrix4* iVP,*pVP;
	Ogre::Matrix4 prevVP;
	Ogre::Camera* mCamera;
	Ogre::Vector3 prevPos;
	Ogre::Quaternion prevOr;
	Ogre::Real mPreviousFPS;
};